﻿using System;
using System.Runtime.Serialization;
using System.Linq;
using LuxDiner.Model.Products;
namespace LuxDiner.Model.Orders
{
    [DataContract]
    public class ProductOrderDetailModel:MBase
    {
        [Model(ConvertType = AttributeType.IgnoreUpdate)]
        [DataMember]
        public int ID { get; set; }
        [Model]
        [DataMember]
        public int OID { get; set; }
        [Model]
        [DataMember]
        public int ProductID { get; set; }
        [Model]
        [DataMember]
        public decimal Quantity { get; set; }
        [Model]
        [DataMember]
        public decimal CostMoney { get; set; }
        [Model]
        [DataMember]
        public string Retention { get; set; }

        #region Help
        [DataMember]
        public ProductModel Product { get; set; }
        [DataMember]
        public string AssistantQuantity
        {
            get
            {
                if (Product != null && Product.AssistantUnitRate != null && Product.AssistantUnitRate > 0 && !string.IsNullOrEmpty(Product.AssistantUnitName))
                {
                    var rate = Product.AssistantUnitRate;
                    var d = (int)Quantity / rate;
                    var m = (int)Quantity % rate;
                    if (d > 0)
                    {
                        var ret = string.Format("{0}{1}", d, Product.AssistantUnitName);
                        if (m > 0)
                            ret += string.Format("{0}{1}", m, Product.UnitName);
                        return ret;
                    }
                }
                return "";
            }
        }
        #endregion
    }

    [DataContract]
    public class ProductOrderDetailCollection : ModelCollectionBase<ProductOrderDetailModel> { }
}
